#include "sqladdpage.h"
#include "ui_sqladdpage.h"

sqlAddPage::sqlAddPage(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::sqlAddPage)
{
    ui->setupUi(this);
}

sqlAddPage::~sqlAddPage()
{
    delete ui;
}


void sqlAddPage::on_btn_Add_clicked()
{
    QSqlQuery query;
    //获取课程编号
    int cNum = ui->cNum_Edit->text().toInt();
    //获取课程名
    QString cName = ui->cName_Edit->text();
    //获取老师姓名
    QString tName = ui->tName_Edit->text();
    //获取学分
    double score = ui->scoreEdit->text().toDouble();

    //课程性质
    QString cNature = ui -> cb_cNature -> currentText();

    //获取开课院系
    QString schoolName = ui->school_cmb->currentText();


    //qDebug() << cNum + ' ' + cName + ' ' + tName;


    //构造sql语句
    QString insertSql = QString(
        "INSERT INTO %1 VALUES(%2,'%3','%4',%5,'%6','%7');"
                ).arg(tableName).arg(cNum).arg(cName).arg(tName).arg(score).arg(cNature).arg(schoolName);
    qDebug() << insertSql;
    //执行sql语句
    query.exec(insertSql);
//    commit 提交交事务
    query.exec("commit");
    QMessageBox::information(NULL, "信息提交", "提交成功");

}

void sqlAddPage::on_btn_clear_clicked()
{
    ui->cName_Edit->setText("");
    ui->cNum_Edit->setText("");
    ui->tName_Edit->setText("");
    ui->scoreEdit->setText("");
}
